// pages/welcome/index.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name: '',
    pwd: '',
    sex: '',
    age: '',
    pianhao: ''
  },

  getsex: function (e) {
    this.data.sex = e.detail.value;
  },

  getage: function (e) {
    this.data.age = e.detail.value;
  },

  getpianhao: function (e) {
    this.data.pianhao = e.detail.value;
  },

  getname: function (e) {
    this.data.name = e.detail.value
  },


  getpwd: function (e) {
    this.data.pwd = e.detail.value
  },

  login: function () {
    var that = this;
    wx.request({
      url: app.globalData.headurl + '/qcustomer/getcustomerOpenid',
      data: {
        cname: that.data.name,
        cpwd: that.data.pwd,
        openid: app.globalData.openid
      },
      method: "POST",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=utf-8",
      },
      success: function (re) {
        app.globalData.customer=re.data;
        wx.showToast({
          title: '登录成功',
        })
        wx.navigateBack({})

      }
    })
  },

  tosign: function () {
    var that = this;
    wx.request({
      url: app.globalData.headurl + '/qcustomer/addcustomer',
      data: {
        name: that.data.name,
        pwd: that.data.pwd,
        age: that.data.age,
        sex: that.data.sex,
        pianhao: that.data.pianhao,
        openid: app.globalData.openid,
        money: 0
      },
      method: "POST",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=utf-8",
      },
      success: function (re) {
        wx.showToast({
          title: '注册成功',
        })
        that.onShow();

      }
    })




  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    wx.request({
      url: app.globalData.headurl + '/qcustomer/getcustomerOpenid',
      data: {
        openid: app.globalData.openid
      },
      method: "POST",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=utf-8",
      },
      success: function (re) {
       that.setData({
         customer:re.data
       })

      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})